define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();
            
            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.length > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });
            
            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            order: function () {

                // 订单
                var OrderTable = $("#OrderTable");

                // 获取选中的ID
                let ids = Fast.api.query('ids') ? Fast.api.query('ids') : 0

                // 初始化表格
                Table.api.init({
                    extend: {
                        index_url: 'teacher/info/follow?ids=' + ids,
                        table: 'subject_teacher_follow', // 表名
                    }
                });

                OrderTable.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    toolbar: '#OrderToolbar',
                    pk:'id',
                    sortName: 'fa_subject_teacher_follow.createtime',
                    sortOrder:'desc',
                    columns: [
                        [
                            {field: 'id', title: 'ID', operate: false},
                            {field: 'business.mobile', title: __('Bmobile'), operate: 'LIKE'},
                            {field: 'business.nickname', title: __('Bnickname'), operate: 'LIKE'},
                            {field: 'business.avatar', title: __('Bavatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                            {field: 'business.gender_text', title: __('Bgender'), operate: false},
                            {field: 'business.province_text', title: __('Bprovince'), operate: 'LIKE'},
                            {field: 'business.city_text', title: __('Bcity'), operate: 'LIKE'},
                            {field: 'business.district_text', title: __('Bdistrict'), operate: 'LIKE'},
                            {field: 'business.email', title: __('Bemail'), operate: 'LIKE'},
                            {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
                        ]
                    ]
                });

                // 为表格1绑定事件
                Table.api.bindevent(OrderTable);
            },
            // comment: function () {

            //     // 评论
            //     var CommentTable = $("#CommentTable");

            //     let ids = Fast.api.query('ids') ? Fast.api.query('ids') : 0

            //     Table.api.init({
            //         extend: {
            //             index_url: 'subject/info/comment?ids=' + ids,
            //             table: 'subject_comment',
            //         }
            //     });

            //     CommentTable.bootstrapTable({
            //         url: $.fn.bootstrapTable.defaults.extend.index_url,
            //         toolbar: '#CommentToolbar',
            //         pk:'id', // 主键
            //         sortName: 'createtime', // 排序字段
            //         sortOrder:'desc', // 排序方式
            //         columns: [
            //             [
            //                 {field: 'id', title: 'ID', operate: false},
            //                 {field: 'business.nickname', title: __('Bnickname'), operate: 'LIKE'},
            //                 {field: 'content', title: __('Ccontent'), operate: 'LIKE'},
            //                 {field: 'createtime', title: __('Ccreatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
            //             ]
            //         ]
            //     });

            //     // 为表格2绑定事件
            //     Table.api.bindevent(CommentTable);
            // }
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});
